#include "SearchWidget.h"
#include <QApplication>

namespace UserManagementSystem {
SearchWidget::SearchWidget(QWidget *parent)
    :FramelessWidget(parent)
{


    m_mainLayout=new QVBoxLayout(this);
    m_subLayout=new QHBoxLayout();
    m_searchLayout=new QHBoxLayout();

    m_createPatientBtn=new QPushButton();
    m_createCaseBtn=new QPushButton();
    m_searchBox=new QFrame();
    m_searchLabel=new QLabel();
    m_inputEdit=new QLineEdit();
    m_filterBtn=new QPushButton();
    m_sortBtn=new QPushButton();

    LoadIcon();
    InitDedaultLayout();
}

void SearchWidget::InitDedaultLayout()
{

    //布局向左靠近
    // m_mainLayout->setAlignment(Qt::AlignLeft);


    m_searchBox->setLayout(m_searchLayout);
    m_searchLayout->addWidget(m_searchLabel);
    m_searchLayout->addWidget(m_inputEdit);

    m_subLayout->addWidget(m_searchBox);
    m_subLayout->addWidget(m_filterBtn);
    m_subLayout->addWidget(m_sortBtn);

    //按钮的布局
    QHBoxLayout* btns_layout=new QHBoxLayout();
    btns_layout->addWidget(m_createPatientBtn);
    btns_layout->addWidget(m_createCaseBtn);


    m_mainLayout->addLayout(btns_layout);
    m_mainLayout->addLayout(m_subLayout);



    InitDefaultStyle();
}

void SearchWidget::InitDefaultStyle()
{


    //新建患者按钮
    QString create_btn=R"(
    QPushButton {
        background-color: #0078D7;
        border-radius: 15px;
        color: white;
        border: none;
        padding: 8px 16px;
        font-size: 14px;
    }
    QPushButton:hover {
        background-color: #005BB5;
    }
    QPushButton:pressed {
        background-color: #003E8A;
    }
)";
    m_createPatientBtn->setStyleSheet(create_btn);
    m_createCaseBtn->setStyleSheet(create_btn);
    //搜索框样式
    QString remaining_box=R"(
    QWidget {
        border: 1px solid gray;
        border-radius: 10px;
        background-color: white; /* 可选：设置背景色 */
    }
)";
    m_searchBox->setStyleSheet(remaining_box);
    m_filterBtn->setStyleSheet(remaining_box);
    m_sortBtn->setStyleSheet(remaining_box);
    m_searchLabel->setStyleSheet(R"(
    QLabel {
        background-color: transparent;
        border: none;
    }
)");
    m_inputEdit->setStyleSheet(R"(
    QLineEdit {
        background-color: transparent;
        border: none;
    }
)");

    //给按钮设置图标
    m_searchLabel->setPixmap(m_findIcon.pixmap(20,20));
    m_filterBtn->setIcon(m_filterIcon);
    m_sortBtn->setIcon(m_sortIcon);

    m_filterBtn->setIconSize(QSize(25,25));
    m_sortBtn->setIconSize(QSize(25,25));
    m_filterBtn->setFixedSize(50,50);
    m_sortBtn->setFixedSize(50,50);


}

void SearchWidget::LoadIcon()
{
    QString find_path=QApplication::applicationDirPath()+"/res/PatientManager/find.png";
    QString filter_path=QApplication::applicationDirPath()+"/res/PatientManager/filter.png";
    QString sort_path=QApplication::applicationDirPath()+"/res/PatientManager/sort.png";


    //读入资源文件
    m_findIcon.addFile(find_path,QSize(50,50));
    m_filterIcon.addFile(filter_path,QSize(40,40));
    m_sortIcon.addFile(sort_path,QSize(40,40));
}
};

